//
//  UIApplication+TabBar.m
//  Example
//
//  Created by admin on 2020/4/15.
//  Copyright © 2020 admin. All rights reserved.
//

#import "UIApplication+TabBar.h"
#import <RTRootNavigationController/RTRootNavigationController.h>


@implementation UIApplication (TabBar)


-(void)configTabBar{
    
    Class cls1 = NSClassFromString(@"StyleViewController");
    UIViewController *vc1 =  [cls1 new];
    vc1.title = @"样式";
    SuperNavigationController *nav1 = [[SuperNavigationController alloc] initWithRootViewController:vc1];
    
    
    // 视图控制器的分栏按钮
    // 视图控制器的分栏按钮，如果没有被显示创建，并且被使用了，则会自动根据视图控制器的title来创建
    //vc1.tabBarItem;
    
    Class cls2 = NSClassFromString(@"FontAwesomeViewController");
    UIViewController *vc2 =  [cls2 new];
    vc2.title = @"FontAwesome";
    SuperNavigationController *nav2 = [[SuperNavigationController alloc] initWithRootViewController:vc2];
    
    Class cls3 = NSClassFromString(@"HomeViewController");
    UIViewController *vc3 =  [cls3 new];
    vc3.title = @"商家";
    SuperNavigationController *nav3 = [[SuperNavigationController alloc] initWithRootViewController:vc3];
    
    Class cls4 = NSClassFromString(@"PageTesViewtController");
    UIViewController *vc4 =  [cls4 new];
    vc4.title = @"swift";
    SuperNavigationController *nav4 = [[SuperNavigationController alloc] initWithRootViewController:vc4];
    [nav4.tabBarItem setImage:[UIImage imageWithIcon:@"fa-heart" backgroundColor:[UIColor clearColor] iconColor:COLORSUCCESS andSize:CGSizeMake(20, 20)]];
    

    UIViewController *vc5 =  [[Wrapper new] landmarkListSwiftUI];
    vc5.title = @"swiftUI";
    SuperNavigationController *nav5 = [[SuperNavigationController alloc] initWithRootViewController:vc5];
    [nav4.tabBarItem setImage:[UIImage imageWithIcon:@"fa-heart" backgroundColor:[UIColor clearColor] iconColor:COLORSUCCESS andSize:CGSizeMake(20, 20)]];
    
    UITabBarController *tabBarCtrl = [[UITabBarController alloc] init];
    // 把数据中得视图器交给分栏控制器管理
    // 分栏控制器会自动将其管理的视图控制器的分栏按钮(UITabBarItem)放到分栏上显示
    tabBarCtrl.viewControllers = @[nav1, nav2, nav3,nav4,nav5];
    
    // 取到分栏控制器的分栏
    UITabBar *tabBar = tabBarCtrl.tabBar;
    
    // 设置分栏的风格
    tabBar.barStyle = UIBarStyleDefault;
    
    // 是否透明
    tabBar.translucent = NO;
    
    // 设置分栏的前景颜色
    tabBar.barTintColor =[UIColor whiteColor]; ;
    
    // 设置分栏元素项的颜色
    tabBar.tintColor = [UIColor ug_random];
    
    tabBarCtrl.tabBar.tintColor = COLORSUCCESS;
    // 设置窗口的跟视图控制器为分栏控制器
    [UIApplication sharedApplication].keyWindow.rootViewController = tabBarCtrl;
    [self.keyWindow makeKeyAndVisible];
}
@end
